//
//  CRTextTableViewController.swift
//  GZWeibo007
//
//  Created by 雷路荣 on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class CRTextTableViewController: UITableViewController {

    var statuses: [CZStatus]? {
        didSet {
            self.tableView.reloadData()
        }
    }
    
    private let reuseIdentifier = "CRCommentCell"
    override func viewDidLoad() {
        super.viewDidLoad()
        //self.tableView.rowHeight = 98
        self.tableView.estimatedRowHeight = 88
        // 设置cell行高根据约束来自适应
        tableView.rowHeight = UITableViewAutomaticDimension
        //注册
        tableView.registerClass(CRCommentCell.self, forCellReuseIdentifier: reuseIdentifier)
        let since_id = 0 //statuses?.first?.id ?? 0
        let max_id = 0
        CZStatus.mLoadStatus(since_id, max_id: max_id) { (statuses, error) -> () in
            if error != nil {
                return
            }
            self.statuses = statuses
        }
        
    }
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 2
    }
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.statuses?.count ?? 0
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let statues = self.statuses![indexPath.row]
        let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CRCommentCell
        cell.status = statues
        return cell
    }
    


}
